// 导入api
import { userAccountLogin } from '@/api/user'
// 用户信息数据
export default {
  namespaced: true,
  state: () => ({
    // 个人用户信息
    profile: {
      id: '',
      account: '',
      nickname: '',
      avatar: '',
      token: '',
      mobile: ''
    }
  }),
  mutations: {
    // 设置存入用户信息
    setUserInfo (state, userInfo) {
      state.profile = userInfo
    },
    // 清空用户信息
    removeUserInfo (state) {
      state.profile = {}
    }
  },
  actions: {
    async   asyncSetUser (ctx, { account, password }) {
      const res = await userAccountLogin({ account, password })
      // 调用mutations方法给state数据赋值
      ctx.commit('setUserInfo', res.data.result)
    }
  }
}
